import objectdraw.*; import java.awt.*; import java.util.Random; public class colorGrid extends FrameWindowController { private FilledRect[][] grids; private Random rand; public void begin() { grids = new FilledRect[10][10]; rand = new Random(); for( int y = 0 ; y < grids[0].length ; y++) { for( int x = 0; x < grids.length; x++) { grids[x][y] = new FilledRect(100 + x*20, 100 + y*20, 20 , 20, canvas); grids[x][y].setColor( new Color( rand.nextInt(255),rand.nextInt(255),rand.nextInt(255))); } } } }
You need to enable Javascript in your browser to edit pages.
help on how to format text
2D array start with a variable type follow by two []s.
- example: double[] [] x = new double [3] [5]
this make an array of 3 rows and 5 colslike normal array, to modify an 2D array can be done like this: x[1] [1] = 2.0;
To found the rows and columns of a two 2D array:
for example:
this make FilledRect like this :